package com.woniuxy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.entity.RbacRole;
import com.woniuxy.result.Result;
import com.woniuxy.service.RbacRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author linKe
 * @since 2021-11-25
 */
@RestController
@RequestMapping("/rbacRole")
@Api(value="角色接口",tags="rbacRoleApi")
public class RbacRoleController {
    @Resource
    private RbacRoleService rbacRoleService;

    @GetMapping("/one/{id}")
    @ApiOperation(value="根据ID查询管理员",notes="返回管理员")
    public Result<RbacRole> findOneRoleById(@PathVariable int id){
        return new Result<>("200","ok",rbacRoleService.findOneById(id));
    }
    @GetMapping("/one/all")
    @ApiOperation(value="查询所有管理员",notes="返回所有管理员")
    public Result<List<RbacRole>> findAllRole(){
        return new Result<>("200","ok",rbacRoleService.findAllRole());
    }
    @PostMapping("/one/")
    @ApiOperation(value="新增管理员",notes="返回结果1表示成功，0表示失败")
    public Result<Integer> addRole( RbacRole rbacRole){
        return new Result<>("200","ok",rbacRoleService.addRole(rbacRole));
    }

    @PutMapping("/one/")
    @ApiOperation(value="更新管理员",notes="返回结果1表示成功，0表示失败")
    public Result<Integer> updateRole( RbacRole rbacRole){
        int row = rbacRoleService.updateRole(rbacRole);
        return new Result<>("200","ok",row);
    }

    @DeleteMapping("/one/{id}")
    @ApiOperation(value="根据ID删除管理员",notes="返回结果1表示成功，0表示失败")
    public Result<Integer> deleteRole(@PathVariable int id){
        return new Result<>("200","ok",rbacRoleService.deleteRole(id));
    }

    @GetMapping("/findPage/{currentPage}/{size}")
    @ApiOperation(value="无限定条件分页查询",notes="返回分页后的结果集")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    paramType="path",name="currentPage",value="当前页",
                    dataType="Int",required=true),
            @ApiImplicitParam(
                    paramType="path",name="size",value="每页显示条数",
                    dataType="Int",required=true)
    })
    public Result<Page<RbacRole>> findPage(@PathVariable("currentPage") int currentPage, @PathVariable("size") int size){
        return new Result<>("200","ok",rbacRoleService.findAllPage(currentPage,size));
    }


//    @GetMapping("/findPage/")
//    public Result<List<RbacRole>> findPage(@RequestBody() RbacRole rbacRole){
//        return new Result<>("200","ok",rbacRoleService.findAllPage(currentPage,size));
//    }
}
